//
//  ViewController.m
//  UI20_Work
//
//  Created by dllo on 16/8/10.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "ViewController.h"
#import "GDataXMLNode.h"
#import "Perform.h"
#import "SecModel.h"
@interface ViewController ()
@property (nonatomic, strong) NSMutableArray *DOMArray;
@property (nonatomic, strong) NSMutableArray *secArray;
@end

@implementation ViewController
- (IBAction)DOM:(id)sender {
    self.DOMArray = [NSMutableArray array];
    self.secArray = [NSMutableArray array];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"work" ofType:@".xml"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSError *error = nil;
    GDataXMLDocument *document = [[GDataXMLDocument alloc] initWithData:data options:0 error:&error];
    GDataXMLElement *rootElement = [document rootElement];
    NSArray *childArray = rootElement.children;
    for (GDataXMLElement *element in childArray) {
        if ([element.name isEqualToString:@"results"]) {
            for (GDataXMLElement *secElement in element.children) {
                Perform *per = [Perform new];
                [self.DOMArray addObject:per];
                for (GDataXMLElement *childElement in secElement.children) {
                    [per setValue:childElement.stringValue forKey:childElement.name];
                }
            }
        } else {
            SecModel *sec = [SecModel new];
            [self.secArray addObject:sec];
            for (GDataXMLElement *secElement in element.children) {
                [sec setValue:secElement.stringValue forKey:secElement.name];
            }
        }
    }
    NSLog(@"%@", self.DOMArray);
    NSLog(@"%@", self.secArray);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
